# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=ld-shatner
pkgver=4.5c215c4
pkgrel=3
groups=('blackarch' 'blackarch-backdoor' 'blackarch-binary')
pkgdesc='ld-linux code injector.'
arch=('x86_64' 'aarch64')
url='https://github.com/sduverger/ld-shatner'
license=('custom:unknown')
depends=('gcc-libs' 'gcc')
makedepends=('git')
source=("git+https://github.com/sduverger/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i 's|ld-shatner.c -o $@|ld-shatner.c -m32 -o $@|' Makefile
}

build() {
  cd $pkgname

  _opt=""

  gcc -fpie -c obj.c -o obj.o
  ld -pie obj.o -o obj.elf -e func

  _opt="-m32"

  gcc hooked.s "$pkgname.c" $_opt -o $pkgname

  gcc interpatch.c -o interpatch

  #make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgnmae"

  cp -a interpatch $pkgname obj.elf "$pkgdir/usr/share/$pkgname/"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README

  ln -s "/usr/share/$pkgname/$pkgname" "$pkgdir/usr/bin/$pkgname"
  ln -s "/usr/share/$pkgname/interpatch" "$pkgdir/usr/bin/interpatch"
}

